/**
 *
 * Copyright (c) 2012 NCS Corporation.
 *
 * Author: tangb
 * Created Date: May 30, 2012
 * 
 * 	version					author					remark
 * 	1.0						tangb				
 */
package com.ocgs.base.core.web.interceptor;

import com.ocgs.base.core.exception.WebException;
import com.ocgs.base.core.web.action.IBaseAction;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class BaseActionInterceptor extends AbstractInterceptor implements HttpSessionListener {

	private static final long serialVersionUID = 723423402098887688L;
	private static final Log log = LogFactory.getLog(BaseActionInterceptor.class);

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {

		log.info("-----------into the intercept---------------");

		if (!(invocation.getAction() instanceof IBaseAction)) {
			throw new WebException("Action must implements IBaseAction!");
		}
		try {
			IBaseAction action = (IBaseAction) invocation.getAction();
//			action.beginInvoke();
			String result = invocation.invoke();
//			action.endInvoke();
			return result;
		} catch (Exception wae) {
			return "error";
		}
	}

	public void sessionCreated(HttpSessionEvent httpSessionEvent) {
	}

	public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
	}

}
